﻿
Imports System.IO
Imports System.Net
Imports osi.root.delegates
Imports osi.root.formation
Imports osi.root.procedure
Imports osi.service.convertor

Public Class questioner
    Public ReadOnly post_question As _func(Of Stream, 
                                              Int64, 
                                              pointer(Of HttpStatusCode), 
                                              pointer(Of WebHeaderCollection), 
                                              pointer(Of String), 
                                              event_comb)
    Public ReadOnly get_question As Func(Of String, 
                                            pointer(Of HttpStatusCode), 
                                            pointer(Of WebHeaderCollection), 
                                            pointer(Of String), 
                                            event_comb)

    Public Sub New(ByVal host As String,
                   ByVal port As String,
                   ByVal connect_timeout_ms As String,
                   ByVal response_timeout_ms As String,
                   ByVal buff_size As String,
                   ByVal single_copy_timeout_ms As String,
                   ByVal copy_timeout_ms As String,
                   ByVal max_content_length As String)
        Dim sls As link_status = Nothing
        Dim rls As link_status = Nothing
        sls = New link_status(connect_timeout_ms.to_int64(constants.default_value.connect_timeout_ms),
                              buff_size.to_int32(constants.default_value.buff_size),
                              single_copy_timeout_ms.to_int64(constants.default_value.single_copy_timeout_ms),
                              copy_timeout_ms.to_int64(constants.default_value.copy_timeout_ms),
                              max_content_length.to_int64(constants.default_value.max_content_length))
        rls = New link_status(response_timeout_ms.to_int64(constants.default_value.response_timeout_ms),
                              buff_size.to_int32(constants.default_value.buff_size),
                              single_copy_timeout_ms.to_int64(constants.default_value.single_copy_timeout_ms),
                              copy_timeout_ms.to_int64(constants.default_value.copy_timeout_ms),
                              max_content_length.to_int64(constants.default_value.max_content_length))
        post_question = Function(s, l, sc, hc, con) client.request(generate_url(host, port.to_uint16()),
                                                                   s,
                                                                   l,
                                                                   sc,
                                                                   hc,
                                                                   con,
                                                                   sls,
                                                                   rls)
        get_question = Function(s, sc, hc, con) client.request(generate_url(host, port.to_uint16(), s),
                                                               sc,
                                                               hc,
                                                               con)
    End Sub
End Class

Public Class post_questioner
    Inherits questioner

    Public Sub New(ByVal host As String,
                   ByVal port As String,
                   ByVal connect_timeout_ms As String,
                   ByVal response_timeout_ms As String,
                   ByVal buff_size As String,
                   ByVal single_copy_timeout_ms As String,
                   ByVal copy_timeout_ms As String,
                   ByVal max_content_length As String)
        MyBase.New(host,
                   port,
                   connect_timeout_ms,
                   response_timeout_ms,
                   buff_size,
                   single_copy_timeout_ms,
                   copy_timeout_ms,
                   max_content_length)
    End Sub

    Public Shared Operator +(ByVal this As post_questioner) As _func(Of Stream, 
                                                                        Int64, 
                                                                        pointer(Of HttpStatusCode), 
                                                                        pointer(Of WebHeaderCollection), 
                                                                        pointer(Of String), 
                                                                        event_comb)
        If this Is Nothing Then
            Return Nothing
        Else
            Return this.post_question
        End If
    End Operator
End Class

Public Class get_questioner
    Inherits questioner

    Public Sub New(ByVal host As String,
                   ByVal port As String,
                   ByVal connect_timeout_ms As String,
                   ByVal response_timeout_ms As String,
                   ByVal buff_size As String,
                   ByVal single_copy_timeout_ms As String,
                   ByVal copy_timeout_ms As String,
                   ByVal max_content_length As String)
        MyBase.New(host,
                   port,
                   connect_timeout_ms,
                   response_timeout_ms,
                   buff_size,
                   single_copy_timeout_ms,
                   copy_timeout_ms,
                   max_content_length)
    End Sub

    Public Shared Operator +(ByVal this As get_questioner) As Func(Of String, 
                                                                      pointer(Of HttpStatusCode), 
                                                                      pointer(Of WebHeaderCollection), 
                                                                      pointer(Of String), 
                                                                      event_comb)
        If this Is Nothing Then
            Return Nothing
        Else
            Return this.get_question
        End If
    End Operator
End Class
